/*

dp[i][j]=字符串A到第i位与字符串B到第j位的最长公共子序列长度
if a[i]==b[j]:
    dp[i][j]=dp[i-1][j-1]+1
else:
    dp[i][j]=max(
        dp[i-1][j],
        dp[i][j-1]
    )

*/


#include <algorithm>
#include <iostream>
#include <istream>
#include <string>
#include <vector>

using ll = int64_t;

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::string a,b;
    std::vector<std::vector<ll>> dp;
    while (std::cin>>a>>b) {
        ll n=a.size(),m=b.size();
        a=' '+a;
        b=' '+b;
        dp.clear();
        dp.resize(n+1,std::vector<ll>(m+1));
        for(ll i=1;i<=n;i++){
            for(ll j=1;j<=m;j++){
                if(a[i]==b[j]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }else{
                    dp[i][j]=std::max(
                        dp[i-1][j],
                        dp[i][j-1]
                    );
                }
            }
        }
        std::cout<<dp[n][m]<<"\n";
    }
}